﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TKToXML
{
    public class Request
    {
        public string Function { get; set; }
        public string MaDV { get; set; }
        public string MaHQ { get; set; }
        public string MessageId { get; set; }                
        public string Reference { get; set; }
        public string Type { get; set; }
        public string TenDV
        {
            get
            {
                using (var context = new ECUSTOMSEntities())
                {
                    var donVi = context.SDONVIs.Where(dv => dv.Ma == MaDV).First();

                    return donVi.Ten_U;
                }
            }
        }        
        public string TenHQ
        {
            get
            {
                using (var context = new ECUSTOMSEntities())
                {
                    var haiQuan = context.SHAIQUANs.Where(hq => hq.Ma == MaHQ).First();

                    return haiQuan.Ten_U;
                }
            }
        }
                
        public string ToXML()
        {
            string result = "";
            result += "<Envelope>";
                result += "<Header>";
                    result += "<procedureType>2</procedureType>";
                    result += "<Reference>";
                        result += "<version>3.00</version>";
                        result += "<messageId>" + MessageId + "</messageId>";
                    result += "</Reference>";
                    result += "<SendApplication>";
                        result += "<name>" + "Test" + "</name>";
                        result += "<version>" + "1.0" + "</version>";
                        result += "<companyName>" + "Phong-CNTT" + "</companyName>";
                        result += "<companyIdentity>" + "0000000000" + "</companyIdentity>";
                        //result += "<createMessageIssue>" + "TCHQ" + "</name>";
                    result += "</SendApplication>";
                    result += "<From>";
                        result += "<name>" + TenDV + "</name>";
                        result += "<identity>" + MaDV + "</identity>";
                    result += "</From>";
                    result += "<To>";
                        result += "<name>" + TenHQ + "</name>";
                        result += "<identity>" + MaHQ + "</identity>";
                    result += "</To>";
                    result += "<VAN><name /><identity /></VAN>";
                    result += "<Subject>";
                        result += "<type>" + Type + "</type>";                      
                        result += "<function>" + Function + "</function>";
                        result += "<reference>" + Reference + "</reference>";
                    result += "</Subject>";
                result += "</Header>";
                result += "<Body>";
                    result += "<Content></Content>";
                result += "</Body>";
            result += "</Envelope>";

            return result;
        }
    }
}
